<?php
/**
 * Created by PhpStorm.
 * User: hoter.zhang
 * Date: 2015/9/10
 * Time: 9:37
 */

namespace app\core\components;


use yii\base\Behavior;
use yii\web\Controller;

class NoCsrf extends Behavior{

    public $actions = [];
    public $controller;
    public function events() {
        return [Controller::EVENT_BEFORE_ACTION => 'beforeAction'];
    }

    public function beforeAction($event) {
        $action = $event->action->id;
        if(in_array($action, $this->actions)) {
            $this->controller->enableCsrfValidation = false;
        }
    }
}

/*
 * public function behaviors()
    {
        return [
            'csrf' => [
                'class' => NoCsrf::className(),
                'controller' => $this,
                'actions' => [
                    'action-name'
                ]
            ]
        ];
    }
 *
 */